New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

matchinitx

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

matchinitx

A good matcher

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by50%
Maintainers
0
Weekly downloads
 
Created
Source

matchinitx

A good matcher

Usage

Install the package

pnpm add matchinitx

Import the package

import { type MatcherRules, useInitxMatcher } from 'matchinitx'

Basic usage

interface CustomField {
  name: string
}

function resultFn(rule: CustomField, ...others: string[]) {
  return { rule, others }
}

const rules: MatcherRules<CustomField> = [
  {
    matching: [
      'foo',
      /^bar/
    ],
    name: 'first'
  },
  {
    matching: [
      'test',
      /^t/
    ],
    name: 'second'
  }
]

const matcher = useInitxMatcher(resultFn)

matcher.match(rules, 'foo')
// [{ rule: { name: 'first' }, others: [] }]

matcher.match(rules, 'barfoo')
// [{ rule: { name: 'first' }, others: [] }]

matcher.match(rules, 'test')
// [{ rule: { name: 'second' }, others: [] }]

matcher.match(rules, 'top', 'extra')
// [{ rule: { name: 'second' }, others: ['extra'] }]

Type matcher

interface CustomField {
  title: string
}

function resultFn(rule: CustomField, type: string, ...others: string[]) {
  return { rule, type, others }
}

enum CustomType {
  FOO = 'foo',
  BAR = 'bar'
}

const rules: MatcherRules<CustomField> = {
  [CustomType.FOO]: {
    matching: [
      'f',
      'o'
    ],
    title: 'a good matcher'
  },
  [CustomType.BAR]: {
    matching: [
      'b',
      'a'
    ],
    title: 'a good title'
  }
}

const matcher = useInitxMatcher(resultFn)

matcher.match(rules, 'f')
matcher.match(rules, 'o')
// [{ rule: { title: 'a good matcher' }, type: 'foo', others: [] }]

matcher.match(rules, 'b', 'extra')
matcher.match(rules, 'a', 'extra')
// [{ rule: { title: 'a good title' }, type: 'bar', others: ['extra'] }]

Keywords

FAQs

Package last updated on 10 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc